/**
 * 
 */
package name.nano.client.view;

import name.nano.client.FrisbeeTacticBoard;
import gwt.canvas.client.Canvas;

import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.dom.client.MouseDownEvent;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;

public final class MyCanvas extends Canvas {

	public MyCanvas(FrisbeeTacticBoard simulator) {
		super();
		MouseListenerImplementation mouseHandler = new MouseListenerImplementation(simulator);
	    addHandler(mouseHandler, MouseDownEvent.getType());
	    addHandler(mouseHandler, MouseUpEvent.getType());
	    addHandler(mouseHandler, MouseMoveEvent.getType());
	    addHandler(mouseHandler, MouseMoveEvent.getType());
	   
	    addMouseListener(mouseHandler);
	    
	}

	@Override
	public void onBrowserEvent(Event event) {
	    switch (DOM.eventGetType(event)) {
	      case Event.ONMOUSEOVER:
	        // Only fire the mouse over event if it's coming from outside this
	        // widget.
	      case Event.ONMOUSEOUT:
	        // Only fire the mouse out event if it's leaving this
	        // widget.
	        Element related = event.getRelatedTarget();
	        if (related != null && getElement().isOrHasChild(related)) {
	          return;
	        }
	        break;
	    }
	    DomEvent.fireNativeEvent(event, this, this.getElement());
	}
	
	
}